<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.text.*"%>
<%@page import="news.entity.*"%>
<%@page import="news.bll.comments.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'do_addcomment.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <%
    	request.setCharacterEncoding("utf-8");
    	String cip = request.getParameter("cip");
    	String cauthor = request.getParameter("cauthor");
    	String ccontent = request.getParameter("ccontent");
    	int cnid = Integer.parseInt(request.getParameter("cnid"));
    	//SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	//String cdate = df.format(new Date());
    	Date cdate = new Date();
    	Comment comment = new Comment(cnid, ccontent, cdate, cip, cauthor);
    	CommentsDaoImpl cdi = new CommentsDaoImpl();
    	int result = cdi.addComment(comment);
    	if(result>0){
    		%>
    		<script>
    			alert("评论添加成功！");
    			window.location="news_read.jsp?nid=<%=cnid %>";
    		</script>    		
    		<%
    	}else{
    		%>
    		<script>
    			alert("评论添加失败！");
    			window.location="news_read.jsp?nid=<%=cnid %>";
    		</script>    		
    		<%
    	}
    	
    %>
  </body>
</html>
